﻿using System;   
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

using Alicanto.Helpers;
using Alicanto.Lexing;

namespace Alicanto.Compilation.Code.Blocks
{
    internal class Return : ICodeGenerator
    {
        public Expression Code { get; private set; }

        public IEnumerable<ParseInstruction> Generate(TokenSequence tokens, Scope scope)
        {
            // Function parameters
            ParseExpression expression = new ParseExpression();
            yield return expression;

            this.Code = Expression.Return(
                scope.ResolveLabel("return"),
                Expression.Convert(
                    expression.Expression,
                    scope.ResolveLabel("return").Type
                )
            );
        }
    }
}
